package com.thlws.redis.datatype;

import redis.clients.jedis.Jedis;

import java.util.Set;

/**
 * Set 与 SortedSet 区别是：
 *  SortedSet 多一个 score 属性
 * @author HanleyTang
 * @date 2018-12-15
 */
public class JedisSortedSet {

    public static void main(String[] args) {

        try(Jedis jedis = new Jedis("localhost",6379);){

            jedis.zadd("sset",100,"hanley");
            jedis.zadd("sset",70,"jack");
            jedis.zadd("sset",50,"mily");
            jedis.zadd("sset",90,"rose");

            //得到某个元素的score
            double score = jedis.zscore("sset", "rose");

            //给某个元素增加 score
            jedis.zincrby("sset", 8, "mily");

            //取得score区间的元素
            Set<String> stringSet = jedis.zrangeByScore("sset", 60, 101);
            for (String v: stringSet
                 ) {
                System.out.println(v);
            }
        }

    }
}
